<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title>{{number}}.{{title}} | CodePioneer</title>
    <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;600;700&display=swap">
    <!-- 引入ACE插件 -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js" type="text/javascript" charset="utf-8"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ext-language_tools.js" type="text/javascript" charset="utf-8"></script>
    <!-- 引入jquery CDN -->
    <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
    <style>
        :root {
            --primary-color: #2563eb;    /* 主色调-科技蓝 */
            --hover-color: #1d4ed8;     /* 悬停加深色 */
            --bg-overlay: rgba(10, 25, 47, 0.92); /* 背景覆盖色 */
            --text-primary: #f8f9fa;    /* 主文字色 */
            --text-secondary: #e0f2fe;  /* 次文字色 */
            --card-bg: rgba(255, 255, 255, 0.05); /* 卡片背景色 */
        }

        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            -webkit-tap-highlight-color: transparent;
        }

        html {
            font-size: 16px;
            scroll-behavior: smooth;
        }

        body {
            min-height: 100vh;
            font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
            line-height: 1.6;
            background: linear-gradient(var(--bg-overlay), var(--bg-overlay)), 
                        url('https://picsum.photos/1920/1080?random=3') center/cover fixed;
        }

        .container {
            display: flex;
            flex-direction: column;
            min-height: 100vh;
        }

        /* 导航栏 */
        .navbar {
            padding: 0 2rem;
            background: rgba(255, 255, 255, 0.05);
            backdrop-filter: blur(10px);
            border-bottom: 1px solid rgba(255, 255, 255, 0.1);
        }

        .nav-content {
            max-width: 1200px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            height: 60px;
        }

        .nav-links {
            display: flex;
            align-items: center;
            gap: 2rem;
        }

        .nav-links a, .nav-actions a {
            color: var(--text-secondary);
            text-decoration: none;
            font-weight: 500;
            padding: 0.5rem 1rem;
            border-radius: 4px;
            transition: all 0.3s ease;
        }

        .nav-links a:hover {
            color: var(--text-primary);
            background-color: rgba(255, 255, 255, 0.1);
        }

        .nav-actions {
            display: flex;
            gap: 1rem;
        }

        /* 题目内容区 */
        .question-content {
            flex: 1;
            max-width: 1200px;
            margin: 2rem auto;
            padding: 2rem;
            display: grid;
            grid-template-columns: 1fr 1fr;
            gap: 2rem;
        }

        .description-card {
            background: var(--card-bg);
            border-radius: 12px;
            backdrop-filter: blur(8px);
            border: 1px solid rgba(255, 255, 255, 0.1);
            padding: 2rem;
            overflow-y: auto;
            max-height: calc(100vh - 180px);
        }

        .description-card h3 {
            color: var(--text-primary);
            font-size: 1.5rem;
            margin-bottom: 1.5rem;
            border-bottom: 2px solid var(--primary-color);
            padding-bottom: 0.5rem;
        }

        .description-card pre {
            color: var(--text-secondary);
            font-size: 1rem;
            white-space: pre-wrap;
            word-wrap: break-word;
            font-family: 'Inter', sans-serif;
            line-height: 1.8;
        }

        /* 代码编辑器 */
        .code-editor {
            background: var(--card-bg);
            border-radius: 12px;
            backdrop-filter: blur(8px);
            border: 1px solid rgba(255, 255, 255, 0.1);
            padding: 1rem;
        }

        .ace_editor {
            height: calc(100vh - 200px) !important;
            border-radius: 8px;
            font-size: 15px;
        }

        /* 提交区域 */
        .submit-area {
            max-width: 1200px;
            margin: 0 auto 2rem;
            padding: 0 2rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .result-card {
            background: var(--card-bg);
            border-radius: 8px;
            padding: 1rem 1.5rem;
            border: 1px solid rgba(255, 255, 255, 0.1);
            min-width: 300px;
        }

        .result-card pre {
            color: var(--text-secondary);
            font-size: 0.9375rem;
            font-family: 'Inter', sans-serif;
        }

        .btn-submit {
            padding: 0.875rem 2rem;
            background-color: var(--primary-color);
            color: white;
            font-size: 1rem;
            font-weight: 600;
            border: none;
            border-radius: 8px;
            cursor: pointer;
            transition: transform 0.2s ease, box-shadow 0.2s ease;
            box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
        }

        .btn-submit:hover {
            transform: translateY(-2px);
            background-color: var(--hover-color);
            box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
        }

        /* 响应式设计 */
        @media (max-width: 1024px) {
            .question-content {
                grid-template-columns: 1fr;
                margin: 1rem;
                padding: 1rem;
            }

            .description-card {
                max-height: unset;
            }

            .ace_editor {
                height: 400px !important;
            }
        }

        @media (max-width: 768px) {
            .navbar {
                padding: 0 1rem;
            }

            .nav-links {
                gap: 1rem;
            }

            .nav-links a {
                padding: 0.5rem 0.75rem;
            }

            .submit-area {
                flex-direction: column;
                gap: 1rem;
                padding: 0 1rem;
            }

            .result-card {
                width: 100%;
                min-width: auto;
            }
        }

        @media (max-width: 576px) {
            .nav-links {
                display: none; /* 移动端可扩展为汉堡菜单 */
            }
        }
    </style>
</head>

<body>
    <div class="container">
        <!-- 导航栏 -->
        <nav class="navbar">
            <div class="nav-content">
                <div class="nav-links">
                    <a href="/">首页</a>
                    <a href="/all_question">题库</a>
                    <a href="#">竞赛</a>
                    <a href="#">社区</a>
                    <a href="#">求职</a>
                </div>
                <div class="nav-actions">
                    <a href="#">联系我们</a>
                    <a href="#" style="background-color: var(--primary-color); color: white; border-radius: 4px;">登录</a>
                </div>
            </div>
        </nav>

        <!-- 题目内容 -->
        <div class="question-content">
            <!-- 题目描述 -->
            <div class="description-card">
                <h3><span id="number">{{number}}</span>.{{title}} {{star}}</h3>
                <pre>{{desc}}</pre>
            </div>

            <!-- 代码编辑器 -->
            <div class="code-editor">
                <pre id="code" class="ace_editor"><textarea class="ace_text-input">{{pre_code}}</textarea></pre>
            </div>
        </div>

        <!-- 提交区域 -->
        <div class="submit-area">
            <div class="result-card result"></div>
            <button class="btn-submit" onclick="submit()">提交代码</button>
        </div>
    </div>

    <script>
        // 初始化ACE编辑器
        const editor = ace.edit("code");
        editor.setTheme("ace/theme/monokai"); // 保留经典代码主题
        editor.session.setMode("ace/mode/c_cpp");
        editor.setFontSize(16);
        editor.getSession().setTabSize(4);
        editor.setReadOnly(false);
        
        // 启用自动完成
        ace.require("ace/ext/language_tools");
        editor.setOptions({
            enableBasicAutocompletion: true,
            enableSnippets: true,
            enableLiveAutocompletion: true
        });

        // 提交代码函数
        function submit() {
            const code = editor.getSession().getValue();
            const number = document.querySelector("#number").textContent;
            const judgeUrl = `/judge/${number}`;

            $.ajax({
                method: 'POST',
                url: judgeUrl,
                dataType: 'json',
                contentType: 'application/json;charset=utf-8',
                data: JSON.stringify({ code, input: '' }),
                success: (data) => showResult(data)
            });
        }

        // 显示结果函数
        function showResult(data) {
            const resultDiv = document.querySelector('.result');
            resultDiv.innerHTML = `
                <pre>状态：${data.status}\n原因：${data.reason}</pre>
            `;
        }
    </script>
</body>

</html>
